package com.example.presentshopping.ui.activity

import BaseRecyclerAdapter
import BaseRecyclerHolder
import android.annotation.SuppressLint
import android.os.Bundle
import android.text.Html
import android.widget.TextView
import com.example.presentshopping.R
import com.example.presentshopping.config.base.BaseMvpActivity
import com.example.presentshopping.config.bean.GroupDetailsBean
import com.example.presentshopping.mvp.presenter.PublicPresenter
import com.example.presentshopping.net.http.HttpRequest
import com.example.presentshopping.net.http.HttpURL
import com.example.presentshopping.utils.ToastUtil
import com.example.presentshopping.utils.tool.GsonUtils
import kotlinx.android.synthetic.main.activity_group_details.*
import kotlinx.android.synthetic.main.activity_ordermly.title_main_tv
import java.text.DecimalFormat


class GroupDetailsActivity : BaseMvpActivity() {


   var groupDetails: GroupDetailsBean?=null
    var ListBean :GroupDetailsBean.DataBean.ListBean ?=null
    var baseRecyclerAdapter: BaseRecyclerAdapter<GroupDetailsBean.DataBean.ListBean>? = null
    var id : String ?=null
    var str= ""
    private var queryInfoPresenter: PublicPresenter? = null

    override val layoutId: Int
        get() = R.layout.activity_group_details

    override fun initView(savedInstanceState: Bundle?) {
        queryInfoPresenter = PublicPresenter(this, true, "加载中....")
        queryInfoPresenter?.attachView(this)
        id =intent.getStringExtra("id")
        queryInfoPresenter?.netWorkRequestPost(
            HttpURL.Req_getteaminfo,
            HttpRequest.getGoodsDetail(id)
        )
        title_main_tv.leftBackImageTv.setOnClickListener { finish() }
        setAdapter()

    }
    fun setAdapter(){
        baseRecyclerAdapter = object : BaseRecyclerAdapter<GroupDetailsBean.DataBean.ListBean>(
            this,
            null,
            R.layout.item_groupdetails
        ){
            @SuppressLint("SetTextI18n")
            override fun convert(
                holder: BaseRecyclerHolder?,
                data: GroupDetailsBean.DataBean.ListBean,
                position: Int,
                isScrolling: Boolean,
                selectedPosition: Int
            ) {
              val  red_paper = holder?.getView<TextView>(R.id.red_paper)
              val show_time = holder?.getView<TextView>(R.id.show_time)
              val teltname =holder?.getView<TextView>(R.id.teltname)
                teltname?.text ="当前第"+(position+1)+"次未拼中"
                red_paper?.text  = "获得 ¥: " +data.red_paper+" 元奖励金 "
                show_time?.text =data.show_time

            }

        }
        recycler_view.adapter =baseRecyclerAdapter
    }
    override fun onDestroy() {
        queryInfoPresenter?.detachView()
        super.onDestroy()
    }


    override fun showToast(msg: String?) {
       ToastUtil.showMsg(msg)
    }

    override fun onSuccess(data: String?) {
        var totalScore = 0.00
        val df = DecimalFormat("0.00")
        groupDetails = GsonUtils.getGson().fromJson(data, GroupDetailsBean().javaClass)
        baseRecyclerAdapter?.setData(groupDetails?.data?.list)
      for (ListBean in groupDetails?.data?.list!!){
          val  score_int =ListBean.red_paper.toDouble()
          totalScore += score_int
      }

        telena.text =Html.fromHtml( "本次未拼中"+ "<font color=\"#ff2555\">"+groupDetails?.data?.list!!.size+"</font>"+"次"+"  累计获得 "+ "<font color=\"#ff2555\">"+df.format(totalScore)+"</font>"+"元奖励金")

    }

    override fun onFailure(e: Throwable?, code: Int, msg: String?, isNetWorkError: Boolean) {

    }
}


